package com.cctc.mychat.client.handler;

import com.cctc.mychat.common.protocol.message.impl.response.LogoutResponseMessage;
import com.cctc.mychat.common.session.SessionManager;
import com.cctc.mychat.common.util.JsonUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class LogoutResponseMessageHandler extends SimpleChannelInboundHandler<LogoutResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LogoutResponseMessage response) throws Exception {
        System.out.println("[LogoutResponseMessageHandler] 注销消息：" + JsonUtils.toJson(response));

        if (response.isSuccess()) {
            SessionManager.unBindSession(ctx.channel());
            System.out.println("注销成功！！！");
        } else {
            System.err.println("注销失败，原因：" + response.getReason());
        }
    }
}
